package com.dahaiwuliang.code.controller.admin;

import com.dahaiwuliang.code.server.ArticleService;
import com.dahaiwuliang.code.server.UserServer;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 管理员 跳转url控制器
 */
@Controller
public class IndexAdminController {

    @Autowired
    private UserServer userServer;

    @Autowired
    private ArticleService articleService;
    @RequiresPermissions(value = "进入管理员主页")
    @RequestMapping("/toAdminUserCenterPage")
    public String toAdminUserCenterPage(){
        return "admin/index";
    }

    @RequiresPermissions(value = "进入管理员主页")
    @RequestMapping("/defaultIndex")
    public ModelAndView defaultIndex(){
        ModelAndView modelAndView = new ModelAndView();

         modelAndView.addObject("userNum",userServer.getCount(null,null,null));
        modelAndView.addObject("todayRegisterNum",userServer.todayRegister());
        modelAndView.addObject("todayLoginNum",userServer.todayLogin());
        modelAndView.addObject("todayPublishNum",articleService.todayPublishNum());
        modelAndView.addObject("noAuditNum",articleService.noAuditNum());
        modelAndView.addObject("articleCountNum",articleService.articleCountNum());
        modelAndView.setViewName("admin/default");
        return modelAndView;
    }
}
